package com.yc.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yc.entity.CartInfo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @ClassName CartinfoDao
 * @since: 2023/9/16 18:29
 * @auth: kirito
 * @description:
 **/
@Mapper
@Repository
public interface CartInfoDao extends BaseMapper<CartInfo> {

    /**
     * 根据会员编号查看
     * @param mno
     * @return
     */
    @Select("select g.gno,gname,tno,price,pics,unit,weight,num,cno, mno " +
            "from goodsinfo g inner join cartinfo c on g.gno = c.gno  " +
            "where mno =#{mno}")
    List<Map<String, Object>> findByMno(Integer mno);

    /**
     * 根据购物车编号更新商品数量
     * @param cartInfo
     * @return
     */
    @Update("update cartinfo set num = num+#{num} where cno =#{cno}")
    int update(CartInfo cartInfo);

    /**
     * 根据购物车编号删除商品
     * @param cartInfo
     * @return
     */
    @Delete("delete from cartinfo where cno =#{cno}")
    int del(CartInfo cartInfo);
}
